# CMakeLists.txt for Boost.Asio examples

# Only build if Boost is found
if(Boost_FOUND)
    # Timer example - basic asio timers
    add_executable(timer_example timer_example.cpp)
    target_link_libraries(timer_example Boost::headers)
    if(UNIX)
        target_link_libraries(timer_example pthread)
    endif()

    # TCP client example
    add_executable(tcp_client_example tcp_client_example.cpp)
    target_link_libraries(tcp_client_example Boost::headers)
    if(UNIX)
        target_link_libraries(tcp_client_example pthread)
    endif()

    # TCP server example
    add_executable(tcp_server_example tcp_server_example.cpp)
    target_link_libraries(tcp_server_example Boost::headers)
    if(UNIX)
        target_link_libraries(tcp_server_example pthread)
    endif()

    # Async operations example
    add_executable(async_operations_example async_operations_example.cpp)
    target_link_libraries(async_operations_example Boost::headers)
    if(UNIX)
        target_link_libraries(async_operations_example pthread)
    endif()

    # UDP example
    add_executable(udp_example udp_example.cpp)
    target_link_libraries(udp_example Boost::headers)
    if(UNIX)
        target_link_libraries(udp_example pthread)
    endif()

    # Custom targets to run examples
    add_custom_target(run_timer_example
        COMMAND timer_example
        DEPENDS timer_example
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Running timer example"
    )

    add_custom_target(run_async_operations_example
        COMMAND async_operations_example
        DEPENDS async_operations_example
        WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
        COMMENT "Running async operations example"
    )

    message(STATUS "Boost.Asio examples configured successfully")
else()
    message(STATUS "Boost not found - Asio examples will not be built")
endif()
